import { createReducer } from '../utils/index'
import { PREVIEW_ORDER_SUCC, PREVIEW_ORDER_FAIL, CREATE_ORDER_SUCC, CREATE_ORDER_FAIL, SHOW_ORDER_SUCC, SHOW_ORDER_FAIL, SHOW_DETAIL_SUCC, SHOW_DETAIL_FAIL } from '../contants/order'

const initialState = {
	isFetched: null,
	orderData: [],
    isPreviewed: null,
    orderPreview: [],
	isCreated: null,
    detailisFetched: null,
    orderDetail:[]
}

export default createReducer(initialState, {
	[PREVIEW_ORDER_SUCC]: (state, payload) => {
		 return Object.assign({}, state, {
			'isPreviewed': true,
			'orderPreview': payload.data
		})
	},

	[PREVIEW_ORDER_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isPreviewed': false,
            'orderPreview': []
        });
    },

    [CREATE_ORDER_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isCreated': true
        });
    },

    [CREATE_ORDER_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isCreated': false
        });
    },

    [SHOW_ORDER_SUCC]: (state, payload) => {
         return Object.assign({}, state, {
            'isFetched': true,
            'orderData': payload.data
        })
    },

    [SHOW_ORDER_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isFetched': false,
            'orderData': []
        });
    },

    [SHOW_DETAIL_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'detailisFetched': true,
            'orderDetail':payload.data
        });
    },

    [SHOW_DETAIL_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'detailisFetched': false,
            'orderDetail':[]
        });
    },
})